package com.beck.util;


import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfPageEventHelper;
import com.itextpdf.text.pdf.PdfWriter;

public class PdfBuilder extends PdfPageEventHelper {

    //Image image;
   // 当当前页面开始加载时，触发(页眉)
   @Override
    public void onOpenDocument(PdfWriter var1, Document var2) {

    }

    @Override
    public void onStartPage(PdfWriter var1, Document var2) {
        System.out.println("页眉");
    }

    @Override
    public void onEndPage(PdfWriter var1, Document var2) {
        System.out.println("页脚");
    }

    @Override
    public void onCloseDocument(PdfWriter var1, Document var2) {
    }


    /**
     * 注意这个函数触发时，该页面并没有创建好，不用利用这个函数添加内容，最好利用onEndPage()处理页面的初始化。
     * @param writer
     * @param document
     */
    /*
    @Override
    public void onStartPage(PdfWriter writer, Document document) {
        // TODO Auto-generated method stub
        super.onStartPage(writer, document);
    }
   // 当当前页面初始化完成，切入document之前触发(页脚)
    @Override
    public void onEndPage(PdfWriter writer, Document document) {
        BaseFont fontChinese=null;
        try {
            fontChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);//设置中文字体
        } catch (  Exception e) {
            e.printStackTrace();
        }

        Font chinese = new Font(fontChinese, 10, Font.NORMAL);
        HeaderFooter header=new HeaderFooter(new com.lowagie.text.Phrase(),false);
        header.setBorderWidth(100f);
        document.addHeader("页眉","这是页眉");
        Rectangle rect = new Rectangle(0, 38, 50, 50);
        // ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
        // new Phrase(String.format("      ", writer.getPageNumber())), (rect.getLeft() + rect.getRight()) / 2,
        // rect.getBottom() - 18, 0);
        ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM,
                new Phrase(String.format("- %d -", writer.getPageNumber() )), (rect.getLeft() + rect.getRight()) / 2,
                rect.getBottom() - 18, 0);
        System.out.println("操作页脚本");
    }*/
}